package com.yy.train.ticket.train.controller;

import java.util.List;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yy.train.ticket.into.page.TrainPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yy.train.ticket.train.entity.TtStationEntity;
import com.yy.train.ticket.train.service.TtStationService;

import com.yy.train.ticket.utils.R;



/**
 * 站点
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-09-25 10:38:44
 */
@RestController
@RequestMapping("tt/station")
public class TtStationController {
    @Autowired
    private TtStationService ttStationService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(){
        List<TtStationEntity> list = ttStationService.list(Wrappers.<TtStationEntity>lambdaQuery());
        return R.ok(list);

    }
    /**
     * 列表
     */
    @PostMapping("/page")
    public R page(@RequestBody TrainPage trainPage){
        LambdaQueryWrapper<TtStationEntity> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.like(StringUtils.isNotBlank(trainPage.getStationName()),TtStationEntity::getStationName,trainPage.getStationName());
        Page<TtStationEntity> pages = new Page<TtStationEntity>(trainPage.getPageNum(), trainPage.getPageSize());
        IPage<TtStationEntity> iPage = ttStationService.page(pages, lambdaQueryWrapper);
        return R.ok(iPage);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{stationId}")
    public R info(@PathVariable("stationId") Long stationId){
		TtStationEntity ttStation = ttStationService.getById(stationId);

        return R.ok(ttStation);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody TtStationEntity ttStation){
		ttStationService.save(ttStation);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody TtStationEntity ttStation){
		ttStationService.updateById(ttStation);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody List<Long> stationIds){
		ttStationService.removeByIds(stationIds);

        return R.ok();
    }

}
